#include "VDLoginWgt.h"
#include "ui_VDLoginWgt.h"

// my
#include "VDUser.h"

VDLoginWgt::VDLoginWgt(QWidget *parent)
	: QDialog(parent, Qt::CustomizeWindowHint)
{
	ui = new Ui::VDLoginWgt();
	ui->setupUi(this);

	ui->checkBoxAuto->setDisabled(true);
	ui->toolButtonEnter->setDisabled(true);

	connect(ui->toolButtonEnter, SIGNAL(clicked()), 
		SLOT(slotToolButtonEnter_clicked()));
	connect(ui->toolButtonExit, SIGNAL(clicked()), 
		SLOT(slotToolButtonExit_clicked()));

	connect(ui->checkBoxAuto, SIGNAL(toggled(bool)), 
		SLOT(slotCheckBoxAuto_toggled(bool)));

	connect(ui->lineEditLogin, SIGNAL(textChanged(const QString&)), 
		SLOT(slotLineEditLogin_textChanged(const QString&)));
	connect(ui->lineEditPassword, SIGNAL(textChanged(const QString&)), 
		SLOT(slotLineEditPassword_textChanged(const QString&)));
}

VDLoginWgt::~VDLoginWgt()
{
	delete ui;
}

VDUser * VDLoginWgt::getUser()
{
	return VDUser::makeNew(ui->lineEditLogin->text());
}

void VDLoginWgt::slotToolButtonEnter_clicked()
{
	if (isEnter())
	{
		accept();
	}
}

void VDLoginWgt::slotToolButtonExit_clicked()
{
	reject();
}

void VDLoginWgt::slotCheckBoxAuto_toggled( bool checked )
{

}

void VDLoginWgt::slotLineEditPassword_textChanged( const QString &text )
{
	bool enable = !ui->lineEditLogin->text().isEmpty();
	ui->checkBoxAuto->setEnabled(enable);
	ui->toolButtonEnter->setEnabled(enable);
}

void VDLoginWgt::slotLineEditLogin_textChanged( const QString &text )
{
	bool enable = !ui->lineEditLogin->text().isEmpty();
	ui->checkBoxAuto->setEnabled(enable);
	ui->toolButtonEnter->setEnabled(enable);
}

bool VDLoginWgt::isEnter()
{
	//ui->lineEditLogin->text();
	//ui->lineEditPassword->text();
	return true;
}

